#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
priority_queue<ll, vector<ll>, greater<ll>> pq;
const ll MOD = 998244353;
const ll N = 2e6 + 10;
ll  L[N], R[N], pre[N],C[N];
map<ll, ll> mp;
ll now = 0;
ll init(ll a, ll b, ll c)
{
    a = a + 1, b = b + 1;
    c = c * 3;
    c++;
    return a * b + c;
}
int main()
{
    fast();
    ll m = 1000;
    init(1, 1, m);
    init(2, 2, m);
    ll T = 1;
    for (ll i = 1; i <= m; i++)
    {
        ll x;
        x = 2 * i + 1;
        pq.push(x);
    }
    cin >> T;
    vector<ll> V;
    while (T--)
    {
        V.clear();
        ll n;
        cin >> n;
        for (ll i = 0; i < n; i++)
        {
            ll a;

            cin >> a;
            if (C[a] == 0)
            {
                L[a] = i;
                V.push_back(a);
                now = 0;
            }
            C[a]++;
            R[a] = i;
            now += i;
        }
        vector<ll> G(n + 1);
        now = 0;

        bool flag = 1;
        for (auto &x : V)
        {
            ll f = C[x]+x*x*now;
            if (R[x] - L[x] + 1 != f || (f & (f + 1)) != 0)
            {
                flag = false;
                now = now * now;
                break;
            }
        }
        if (flag)
        {
            yes;
        }
        else
            no;
        for (auto &x : V)
        {
            C[x] = 0;
        }
    }
    int qq = 0;
    while (pq.size() != 1)
    {
        ll x = pq.top();
        pq.pop();
        x += pq.top();
        pq.pop();
        qq += x;
        pq.push(x);
    }
    qq = init(3, 4, qq);
    return 0;
}